<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html lang="en">
<!--<![endif]-->
<!-- BEGIN HEAD -->

<head>
    <meta charset="utf-8" />
    <title></title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta content="width=device-width, initial-scale=1" name="viewport" />
    <meta content="" name="description" />
    <meta content="" name="author" />
    <meta http-equiv="Access-Control-Allow-Origin" content="*" />
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="https://tv.speechb.com/lib/superui/content/ui/global/bootstrap/css/bootstrap.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="https://tv.speechb.com/lib/superui/content/adminlte/dist/css/AdminLTE.css">
    <link rel="stylesheet" href="https://tv.speechb.com/lib/superui/content/adminlte/dist/css/skins/_all-skins.min.css">
    <link href="https://tv.speechb.com/lib/superui/content/min/css/supershopui.common.min.css" rel="stylesheet" />
    <link href="https://tv.speechb.com/lib/superui/content/plugins/bootstrap-table/bootstrap-table.css" rel="stylesheet" />
    <link href="https://tv.speechb.com/lib/superui/content/layx/layx.min.css" rel="stylesheet" />
    <link href="https://tv.speechb.com/lib/x-editable/css/bootstrap-editable.css" rel="stylesheet"/>
    <link href="https://tv.speechb.com/lib/x-editable/css/select2-bootstrap.css" rel="stylesheet"/>
    <link href="https://tv.speechb.com/lib/layui/css/layui.css" rel="stylesheet"/>
    <!--全局通用框架样式 end-->
</head>
<body>

<!-- Main content -->
<section class="content">

    <div class="row">
        <!-- BEGIN SAMPLE TABLE PORTLET-->
        <div class="col-md-12">


            <div id="toolbar" class="btn-group">
                <button id="btn_add" type="button" class="btn btn-default">
                    <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增
                </button>
                <button id="btn_delete" type="button" class="btn btn-default">
                    <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>删除
                </button>
            </div>
            <div class="table-scrollable">
                <table id="table"></table>

            </div>
        </div>
        <!-- END SAMPLE TABLE PORTLET-->

        <div id="modal" class="modal fade">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title"></h4>
                    </div>
                    <div class="modal-body">
                        <div class="form-group">
                            <label>Id</label>
                            <input type="number" class="form-control" name="id" placeholder="id">
                        </div>
                        <div class="form-group">
                            <label>Stars</label>
                            <input type="text" class="form-control" name="name" placeholder="Name">
                        </div>
                        <div class="form-group">
                            <label>用户名</label>
                            <input type="number" class="form-control" name="forks_count" placeholder="用户名">
                        </div>
                        <div class="form-group" >
                            <label>状态</label>
                            <input type="text" class="form-control" name="状态" placeholder="状态">
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-primary submit">保存</button>
                    </div>
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div><!-- /.modal -->
    </div>


    </div>

</section>
<script src="http://tv.speechb.com/lib/superui/content/ui/global/jQuery/jquery.min.js"></script>
<!-- Bootstrap 3.3.6 -->
<script src="https://tv.speechb.com/lib/superui/content/ui/global/bootstrap/js/bootstrap.min.js"></script>

<script src="https://tv.speechb.com/lib/x-editable/js/bootstrap-editable.min.js"></script>

<script src="https://tv.speechb.com/lib/superui/content/min/js/supershopui.common.js"></script>
<script src="https://tv.speechb.com/lib/superui/content/plugins/bootstrap-table/bootstrap-table.js"></script>
<script src="https://tv.speechb.com/lib/superui/content/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.js"></script>
<script src="https://tv.speechb.com/lib/superui/content/layx/layx.min.js"></script>
<script type="text/javascript" charset="utf-8" src="https://tv.speechb.com/lib/toaster/jquery.toaster.js"></script>
<script type="text/javascript" charset="utf-8" src="https://tv.speechb.com/lib/layui/layui.js"></script>
<script type="text/javascript" charset="utf-8" src="/static/admin/js/editable_com.js"></script>
</body>
<script>

    $(function () {
        initBootstrapTable('/admin/config',[{
            checkbox: true
        }, {
            field: 'id',
            title: 'ID',
            visible: false
        }, {
            field: 'sorting',
            title: '序号',
            align: 'center',
            sortable: true,//启用排序
            width: 60,
            formatter: function (value, row, index) {
                var pageSize = $('#table').bootstrapTable('getOptions').pageSize;     //通过table的#id 得到每页多少条
                var pageNumber = $('#table').bootstrapTable('getOptions').pageNumber; //通过table的#id 得到当前第几页
                return pageSize * (pageNumber - 1) + index + 1;    // 返回每条的序号： 每页条数 *（当前页 - 1 ）+ 序号
            }
        }, {
            field: 'key',
            title: '名称',
            align: 'center',
            width: 120,
            formatter: function (value, row, index) {
                return '<a id="' + row.id + 'key"data-type="textarea" value="' + row.key + '">' + value + '</a>';
            }
        }, {
            field: 'value',
            title: '内容',
            formatter: function (value, row, index) {
                return '<a id="' + row.id + 'value"data-type="textarea" value="' + row.value + '">' + value + '</a>';
            }
        }, {
            field: 'desc',
            title: '描述',
            align: 'center',
            width: 280,
            formatter: function (value, row, index) {
                if (value == null || value == '') {
                    value = '暂无描述';
                }
                return '<a id="' + row.id + 'desc"data-type="textarea" value="' + row.desc + '">' + value + '</a>';
            }
        }, {
            field: 'create_time',
            title: '更新日期',
            align: 'center',
            width: 180,
        }, {
            field: 'operation',
            title: '操作',
            align: 'center',
            width: 120,
            events: actionEvents,//给按钮注册事件
            formatter: actionFormatter//表格中增加按钮
        }],function (data) {
            var url = '/admin/config/update';
            for (var i = 0; i < data.rows.length; i++) {
                editableConfig(data.rows[i].id + "key", 'textarea', data.rows[i].id, '配置名称更改', url);
                editableConfig(data.rows[i].id + "value", 'textarea', data.rows[i].id, '配置内容更改', url);
                editableConfig(data.rows[i].id + "desc", 'textarea', data.rows[i].id, '配置描述更改', url);
            }
        });

        $("#btn_add").click(function(){
            layx.iframe('config_publish','添加配置项','/admin/system/add_config');
        });
        $("#btn_delete").click(function(){
            // 批量删除
            var selectRow = $('#table').bootstrapTable('getSelections');
            if (selectRow.length < 1) {
                $.toaster({ priority : "warning", title : "通知", message : "内容未选中！" });
                return false;
            }
            var ids = new Array();
            for(var i=0;i<selectRow.length;i++){
                ids[i]=selectRow[i].id;
            }
            if (confirm('是否批量删除话术?')) {
                $.ajax({
                    url: "/admin/speechcraft/delete_list",
                    type: 'delete',
                    data : {
                        "ids":ids,
                    },
                    success: function (data) {
                        console.log(data.code);
                        if(data.code == 1) {
                            $('#table').bootstrapTable('refresh');
                        } else {
                            $.toaster({ priority : "danger", title : "通知", message : "批量删除话术失败!" });
                        }
                    },
                    error: function () {
                        $.toaster({ priority : "danger", title : "通知", message : "批量删除话术失败!" });
                    }
                })
            }
        });


    });
    function actionFormatter(value) {
        return [
            ' <a href="javascript:;" class="btn btn-icon-only purple update "><i class="fa fa-edit "></i></a>'+
            '<a href="javascript:;" class="btn btn-icon-only red remove"> <i class="fa fa-times "></i></a>',
        ].join('');
    }

    // update and delete events
    window.actionEvents = {
        'click .update': function (e, value, row) {
            console.log("点击了");

        },
        'click .update': function (e, value, row, index) {
            layx.iframe('config_publish','添加配置项','/admin/addConfig?id='+row.id);
        },

        'click .remove': function (e, value, row) {
            if (confirm('是否删除话术?')) {
                $.ajax({
                    url: "/admin/speechcraft/delete?id="+row.id,
                    type: 'delete',
                    success: function (data) {
                        console.log(data.code);
                        if(data.code == 1) {
                            $('#table').bootstrapTable('refresh');
                        } else {
                            $.toaster({ priority : "danger", title : "通知", message : "删除话术失败!" });
                        }
                    },
                    error: function () {
                        $.toaster({ priority : "danger", title : "通知", message : "删除话术失败!" });
                    }
                })
            }
        }
    };

</script>
</html>